home *** CD-ROM | disk | FTP | other *** search
- {
- Turbo Pascal Ver 5.0 Unit
- PROGINFO.TPU
- Mar 28, 1989
- Programmer: Rick Housh 72466,212
-
- This unit provides something Borland has left out of version 5.00,
- probably because it is dependent on DOS version 3.xx or higher being
- the operating system. It provides a method for a program to know its
- own name. It requires no other units to operate. Because it needs
- them itself, it also provides public functions to find the segment
- of the program's environment, and the DosVersion. Its function
- DosVersion works exactly like the TP Version 5.00 DosVersion
- function. It returns a word, the low byte of which contains the
- Major Dos version number, and the hi byte of which contains the
- Minor Dos version number. The ProgName function returns a String,
- and the EnvSeg function returns a word containing the segment of
- the environment of the current program.
-
- WARNING : The ProgName function will generate runtime err #255
- if used on a DOS version lower then 3.00.
-
- Requires Borland Turbo Pascal, version 5.00
-
- Proper syntax examples:
- StringVar := ProgName;
- DosMajorByte := lo(DosVersion);
- DosMinorByte := hi(Dosversion);
- EnvSegWord := GetEnvSeg;
- }
-
- Unit ProgInfo;
-
- Interface
-
- Function DosVersion : Word;
- Function GetEnvSeg : Word;
- Function ProgName : String;
-
- Implementation
-
- Function DosVersion : Word;
- {
- Returns a word with the lo(GetDosVersion) byte holding
- the Major version and hi(GetDosVersion) the minor.
- This is here so this unit can be used without the DOS unit.
- }
- var DosV : Word;
- Begin
- Inline(
- $B4/$30/ { MOV AH,$30 ; Get version func.}
- $CD/$21/ { INT $21 ; Call DOS}
- $89/$46/<DosV); { MOV [BP+<DosVer],AX ; Store result }
- DosVersion := DosV; { and return it }
- end;
-
- Function GetEnvSeg : Word;
- {
- Returns a word which contains the segment of the
- current programs environment.
- }
- Begin
- GetEnvSeg := memW[PrefixSeg:$002C]; { Real simple }
- end;
-
- Function ProgName : String;
- var
- DosVer, EnvSeg,
- i, j : Word;
- PName : String[79];
- ch : Char;
-
- begin
- DosVer := DosVersion;
- { If Major is 0, make it 1 }
- If DosVer < 256 then DosVer := DosVer + 256;
- { If lower than three, abort with }
- { error message, and run time error }
- { 255 }
- If lo(DosVer) < 3 then
- begin
- WriteLn('Wrong DOS version (',lo(DosVer),'.',
- hi(DosVer),')');
- WriteLn('Requires 3.00 or higher');
- RunError(255);
- end;
- PName := ''; { Initialize to null string }
- EnvSeg := GetEnvSeg; { Find environment }
- i := 0; { Initialize counter }
- Repeat { Look through environment }
- j := memW[EnvSeg:i];
- inc(i);
- Until j = 0000; { Until two null bytes signal end }
- i := i + 3; { Three bytes further is our program name }
- Repeat
- j := mem[EnvSeg:i];
- PName := PName + chr(j); { Store the name }
- inc(i);
- Until mem[EnvSeg:i] = 0; { up to zero byte at end }
- for i := 1 to Length(PName) do
- begin { Then upcase string (just in case) }
- ch := UpCase(PName[i]);
- PName[i] := ch;
- end;
- ProgName := PName; { and return it }
- end; { Function PName }
-
- end. { Unit ProgInfo }